<script>
	import {
		GetAuthModule,
		GetUserJobKeys,
	} from '@/common/util.js'
	import {
		Platform,
		Storage_Key,
		UserJobsType,
	} from "@/static/config.js"
	export default {
		onLaunch: function(e) {
			
			const searchparams = window.location.search;
			const params = {};
			const regex = /([^?=&]+)=([^&]*)/g;
			let match;
			while (match = regex.exec(searchparams)) {
			    params[match[1]] = decodeURIComponent(match[2]); // 使用decodeURIComponent解码参数值
			}

			if (params.msg||params.userinfo) {
				
				this.$storage.set('userInfo',JSON.parse(params.msg),false); //存储通知信息-异步
				// this.$storage.set('webUserInfo',JSON.parse(params.userinfo),false); //存储通知信息-异步
				let webuserinfo = JSON.parse(params.userinfo);
				
				// 单独处理webuser的job
				let ukeys = GetUserJobKeys(webuserinfo.roles);
				let userkeys = ukeys.length > 0 ? ukeys : [UserJobsType[2].key]; //  微信授权 && 未绑定平台账号
				webuserinfo.job = userkeys;
				
				// 1、存储通知信息-同步
				this.$storage.set(Storage_Key
					.web_user_info,
					webuserinfo,
					false
				);
				
				uni.$emit("RefreshUser", {
					key: true,
					msg: webuserinfo
				})
				
				// 刷新首页权限菜单
				uni.$emit("RefreshIndexTabs", {
					key: true,
					msg: webuserinfo
				})
				
			} else {
				let msg = {
					name: '山东世安环保工程有限公司',
					code: '91371725MAC44YCA5R',
					openId:"oYUET7RwVikqqiz9i0xHlf25nspQ"
				}
				this.$storage.set(
					'userInfo',
					msg,
					true
				);
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 刷新角色权限模块
			refreshAuthModule(webUserInfo) {
				let _self = this;
				// 单独处理webuser的job
				let ukeys = GetUserJobKeys(webUserInfo.roles);
				let userkeys = ukeys.length > 0 ? ukeys : [UserJobsType[2].key]; //  微信授权 && 未绑定平台账号
				webUserInfo.job = userkeys;
				
				// 1、存储通知信息-同步
				_self.$storage.set(Storage_Key
					.web_user_info,
					webUserInfo,
					true
				);
				// _self.$storage.set(Storage_Key.user_info_typeindex, '2',false);
				// 2、发送事件
				uni.$emit("RefreshUser", {
					key: true,
					msg: webUserInfo
				})
				
				// 刷新首页权限菜单
				uni.$emit("RefreshIndexTabs", {
					key: true,
					msg: webUserInfo
				})
				// 刷新我的权限菜单
				let authModuleData = GetAuthModule();
				// this.listData1 = GetAuthModule('user-1');
				// this.listData2 = GetAuthModule('user-2');
			},
		}
	}
</script>

<style lang='scss'>
	/* uni.css - 通用组件、模板样式库，可以当作一套ui库应用 */
	@import '@/static/css/uni.scss';
	@import '@/static/font/iconfont.css';
</style>